<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/common/default.jsp"%>
<html>
	<head>
	    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	</head>
	
	<body>
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			
			<ul class="breadcrumb">
				<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
				<li>用户中心</li>
				<li>角色管理</li>
				<li class="active">修改</li>
			</ul>
		</div>
		
		<div class="page-content">
			<div class="page-header">
				<h1>角色管理
					<small>
					<i class="icon-double-angle-right"></i>
					编辑		
					</small>					
				</h1>				
			</div>	
		
			<div class="row">
				<div class="col-xs-12">
				<form class="form-horizontal" onsubmit="return sysRoleInfoUpdate();" role="form" id="sysRoleUpateForm" name="sysRoleUpateForm" method="post">
					<input id="roleId" type="hidden" name="roleId" value="${roleRes.role_id}" />
					<input id="roleCode" type="hidden" name="roleCode" value="${roleRes.roleCode}" />
					<div class="form-group">
						<label class="col-sm-3 control-label no-padding-right" for="form-field-1">角色名称：</label>
						<div class="col-sm-9">
							<input type="text" id="roleName" type="text" name="roleName" value="${roleRes.roleName}" maxlength="100" class="col-xs-10 col-sm-5" required />
						</div>
					</div>	
					
					<div>
						<p>权限配置：</p>
					</div>	
					<table id="sysUserInfoDatas" class="table table-striped table-bordered table-hover"  style="margin-top:5px;">
						<thead>
							<tr>
									<th class="center" style="width: 30px;"></th>
									<th colspan="2">名称</th>
						            <th>类型</th>
						            <th>路径</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach var="res" items="${list}"  varStatus="status">
							<tr  id="userinfo_row_${res.resourceId}" >  
								<td><input type="checkbox" value="${res.resourceId}" name="resourceId"
							        	<c:forEach var="rRes" items="${rResList}"  varStatus="status">
							        		<c:choose>
								        		<c:when test="${res.resourceId ==rRes.resourceId}">checked="checked"</c:when>
							        		</c:choose>
							        	</c:forEach>
							        	/>
							     </td>
							     
							     <td colspan="2" >${res.resName}&nbsp;</td>
						         <td>
						        		<c:choose>
							            	<c:when test="${res.type ==1}">菜单</c:when>
							            	<c:otherwise>按钮</c:otherwise>
							            </c:choose>
						         </td>
						         <td>${res.resUrl}&nbsp;</td>
							</tr>
							
							<c:if test="${res.havechild ==1}">
							<c:forEach var="res1" items="${res.list}"  varStatus="status1">
								<tr  id="userinfo_row_${res1.resourceId}">
							        <td>&nbsp;</td>  
						        	<td style="width: 30px"><input type="checkbox" value="${res1.resourceId}" name="resourceId"
						        	<c:forEach var="rRes" items="${rResList}"  varStatus="status">
						        		<c:choose>
							        		<c:when test="${res1.resourceId ==rRes.resourceId}">checked="checked"</c:when>
						        		</c:choose>
						        	</c:forEach>
						        	/></td>
						        	<td style="text-align:right">${res1.resName}&nbsp;</td>
						        	<td>
						        		<c:choose>
							            	<c:when test="${res1.type ==1}">菜单</c:when>
							            	<c:otherwise>按钮</c:otherwise>
							            </c:choose>
						        	</td>
						        	<td>${res1.resUrl}&nbsp;</td>
						        </tr>
							</c:forEach>
							</c:if>
							
							</c:forEach>
							
							
						</tbody>
					</table>
					
					<div class="clearfix form-actions">
						<div class="col-md-offset-3 col-md-9">
							<button class="btn btn-info" type="submit">
								<i class="icon-ok bigger-110"></i>提交
							</button>
						</div>
					</div>	
				</form>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			function sysRoleInfoUpdate() {
				var resIds_array=new Array();  
				$('input[name="resourceId"]:checked').each(function(){
					resIds_array.push($(this).val());//向数组中添加元素 
				});
				var idstr=resIds_array.join(',');//将数组元素连接起来以构建一个字符串  
				var datastr = new Object();
    			datastr.role_id = $('#roleId').val();
    			datastr.roleName = $('#roleName').val();
    			datastr.roleCode = $('#roleCode').val();
    			datastr.resourceIds = idstr;
    			
				var result = true;
				$.ajax({
    		        async: true,
    		        type:"POST",
    		        data:JSON.stringify(datastr),
    		        url: "${ctx}/sys/role/udpate/",
    		        dataType: "json",
    		        headers : {  
                        'Content-Type' : 'application/json;charset=utf-8'  
                    },
                    success : function(data) {
                		if (data != undefined && data.status != undefined
                				&& data.status.trim() == '0') {
                			result = true;
                			alert("角色修改成功！");
                			window.location.href = "${ctx}/sys/role/listRole";
                		} else {
                			result = false;
                			alert(data.error);
                		}
                	},
    			},"json");
			}
			$(document).ready(
					
				function(){
					$('input[name="resourceId"]').each(function(){
						alert(this.val());	
					});
				}
				
			);
			
		</script>
	</body>
</html>